-
Notifications
You must be signed in to change notification settings - Fork 3
CFM-31_Enrollment_Flows_enable_people_picker_for_self_service #337
CFM-31_Enrollment_Flows_enable_people_picker_for_self_service #337
Conversation
0b5171b
to
ac177db
Compare
Previous Pull Request. It contains the review comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
$petitionId = (int)$request->getQuery('petition_id'); | ||
// We need to check if this is part of an Enrollment Flow | ||
$Petitions = $this->fetchTable('Petitions'); | ||
|
||
// Pull the Petition to find its CO | ||
$petition = $Petitions->get( | ||
$petitionId, | ||
contain: ['EnrollmentFlows' => ['EnrollmentFlowSteps']] | ||
); | ||
|
||
// We need to check the Petitioner Authorization. | ||
$hasAuthorizedUser = $petition->enrollment_flow->authz_type == EnrollmentAuthzEnum::AuthUser | ||
? !empty($auth['external']['user']) : true; | ||
|
||
foreach ($petition->enrollment_flow->enrollment_flow_steps as $step) { | ||
if ($step->plugin == 'CoreEnroller.AttributeCollectors') { | ||
$AttributeCollectors = $this->fetchTable('CoreEnroller.AttributeCollectors'); | ||
$attributeCollectorsRecord = $AttributeCollectors->find() | ||
->where(['enrollment_flow_step_id' => $step->id]) | ||
->contain(['EnrollmentAttributes']) | ||
->first(); | ||
|
||
$mode = $hasAuthorizedUser && $attributeCollectorsRecord->enable_person_find ? 'yes' : 'no'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of special logic for an API controller. While we can probably leave the outermost test (if(People && pick && petition_id)
) in place until we have more use cases to refactor, the actual logic of whether or not the PeoplePicker is enabled should go in PetitionsTable
. Or really in EnrollmentFlowsTable
, but since we have a Petition ID as context here, and there is a similar function PetitionsTable::isApproverForFlow()
already, PetitionsTable::isPersonFindEnabled()
probably makes more sense.
Enable people picker functionality as an AttributeCollector configuration